package com.sumainfor.wx.system.maket.controller.rentadviser;

import com.qiniu.util.Json;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.wx.system.maket.service.RdHousingExcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *
 * <p>
 *
 * @author: zc
 * @create: 2019-08-14 15:34
 **/
@Controller
@RequestMapping("/RdHousingExcController")
public class RdHousingExcController {


    @Autowired
    RdHousingExcService rdHousingExcService;

    /**
     * 查询公共换房申请
     * @author zhoucong
     * @data 2019/8/14
     * @Param
     * @return
     */
    @ResponseBody
    @GetMapping("/getHouShelfIdListpublic")
    public JsonResult getHouShelfIdListpublic(@RequestParam Map<String,Object> params, Pager pager){
        JsonResult result=new JsonResult();
        params.put("ExcState","0");//换房申请状态（0 申请换房中 1已抢单 2租客取消）
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdHousingExcService.getHouShelfIdListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getCommunityList=rdHousingExcService.getHouShelfIdList(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }


    /**
     * 查询私有换房申请
     * @author zhoucong
     * @data 2019/8/14
     * @Param
     * @return
     */
    @ResponseBody
    @GetMapping("/getHouShelfIdList")
    public JsonResult getHouShelfIdList(@RequestParam Map<String,Object> params,Pager pager){
        JsonResult result=new JsonResult();
        params.put("ExcState","1");//换房申请状态（0 申请换房中 1已抢单 2租客取消）
        params.put("ShelfId", ContextUtils.getUserId());//租赁顾问的编号
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdHousingExcService.getHouShelfIdListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdHousingExcService.getHouShelfIdList(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;

    }

    /**
     * 换房申请抢单
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/upHousingExc")
    public JsonResult upHousingExc(@RequestBody Map<String, Object> params) {
        params.put("ExcState",1);//0 申请换房中 1已抢单
        return rdHousingExcService.upHousingExc(params);
    }
    /**
     * 换房申请放弃
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/upHousingExcGive")
    public JsonResult upHousingExcGive(@RequestBody Map<String, Object> params) {
        params.put("ExcState",0);//0 申请换房中 1已抢单
        return rdHousingExcService.upHousingExc(params);
    }
}
